const { v4: uuidv4 } = require('uuid');

// Mock data store
const mockData = {
  users: [
    {
      id: 1,
      username: 'testuser',
      password: '$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewdBPj/RK.s5uIfy', // password: 123456
      nickname: '测试用户',
      avatar: 'https://example.com/avatar1.jpg',
      phone: '13800138000',
      email: 'test@example.com',
      level: 5,
      experience: 1250,
      totalStudyTime: 3600,
      practiceCount: 45,
      achievements: ['初学者', '坚持者'],
      role: 'user',
      createdAt: new Date('2024-01-01T00:00:00Z'),
      updatedAt: new Date('2024-01-01T00:00:00Z')
    }
  ],

  banners: [
    {
      id: 1,
      title: '推普活动',
      description: '提升普通话水平，传承中华文化',
      image: 'https://example.com/banner1.jpg',
      link: '/activity/detail/1',
      sort: 1,
      status: 'active'
    },
    {
      id: 2,
      title: '语音检测新功能',
      description: '全新AI语音评测系统上线',
      image: 'https://example.com/banner2.jpg',
      link: '/detection',
      sort: 2,
      status: 'active'
    }
  ],

  functions: [
    {
      key: 'detection',
      name: '语音检测',
      icon: 'volume-o',
      bgColor: '#e3f2fd',
      iconColor: '#1989fa',
      route: '/detection',
      sort: 1,
      enabled: true
    },
    {
      key: 'study',
      name: '学习中心',
      icon: 'book-o',
      bgColor: '#f3e5f5',
      iconColor: '#9c27b0',
      route: '/study',
      sort: 2,
      enabled: true
    },
    {
      key: 'game',
      name: '小游戏',
      icon: 'game-o',
      bgColor: '#e8f5e8',
      iconColor: '#4caf50',
      route: '/game',
      sort: 3,
      enabled: true
    },
    {
      key: 'daily',
      name: '每日一句',
      icon: 'calendar-o',
      bgColor: '#fff3e0',
      iconColor: '#ff9800',
      route: '/daily',
      sort: 4,
      enabled: true
    }
  ],

  recommendations: [
    {
      id: 1,
      title: '普通话发音技巧入门',
      description: '学习普通话声母、韵母、声调，掌握标准发音。',
      cover: 'https://example.com/course1.jpg',
      rating: 4.8,
      studyCount: 1200,
      type: 'course',
      duration: 3600,
      difficulty: 'beginner'
    },
    {
      id: 2,
      title: '古诗词朗诵技巧',
      description: '通过古诗词朗诵提升语言表达能力和文化素养。',
      cover: 'https://example.com/course2.jpg',
      rating: 4.6,
      studyCount: 800,
      type: 'course',
      duration: 2400,
      difficulty: 'intermediate'
    }
  ],

  activities: [
    {
      id: 1,
      title: '我是普通话达人演讲比赛',
      description: '展示你的普通话水平，赢取丰厚奖品！',
      poster: 'https://example.com/activity1.jpg',
      startTime: '2024-01-01T00:00:00Z',
      endTime: '2024-12-31T23:59:59Z',
      status: 'active',
      participantCount: 1500
    }
  ],

  categories: [
    {
      id: 1,
      name: '发音基础',
      icon: 'volume-o',
      color: '#1989fa',
      courseCount: 25,
      sort: 1
    },
    {
      id: 2,
      name: '语调训练',
      icon: 'music-o',
      color: '#9c27b0',
      courseCount: 18,
      sort: 2
    }
  ],

  courses: [
    {
      id: 1,
      title: '普通话声母发音训练',
      description: '系统学习21个声母的标准发音方法',
      cover: 'https://example.com/course1.jpg',
      instructor: '张老师',
      rating: 4.8,
      studentCount: 1200,
      duration: 3600,
      difficulty: 'beginner',
      price: 99.00,
      originalPrice: 199.00,
      tags: ['基础', '发音'],
      progress: 0,
      isEnrolled: false,
      categoryId: 1
    }
  ],

  detectionTexts: [
    {
      id: 1,
      title: '古诗朗诵',
      content: '床前明月光，疑是地上霜。举头望明月，低头思故乡。',
      pinyin: 'chuáng qián míng yuè guāng, yí shì dì shàng shuāng. jǔ tóu wàng míng yuè, dī tóu sī gù xiāng.',
      level: 'easy',
      category: 'poetry',
      duration: 30,
      standardAudio: 'https://example.com/audio1.mp3'
    }
  ],

  gameContents: [
    {
      id: 1,
      image: 'https://example.com/apple.jpg',
      pinyin: 'píng guǒ',
      standardText: '苹果',
      level: 'easy',
      category: 'fruit',
      audioUrl: 'https://example.com/audio/apple.mp3'
    }
  ],

  dailySentences: [
    {
      id: 1,
      date: '2024-01-01',
      chinese: '学而时习之，不亦说乎？',
      pinyin: 'xué ér shí xí zhī, bù yì yuè hū?',
      english: 'Is it not a pleasure, having learned something, to try it out at due intervals?',
      source: '《论语》',
      audioUrl: 'https://example.com/daily/audio1.mp3',
      difficulty: 'medium',
      tags: ['古文', '教育']
    }
  ],

  notifications: [
    {
      id: 1,
      title: '恭喜您完成今日练习',
      content: '您今天的语音练习表现优秀，获得了5个经验值！',
      type: 'achievement',
      status: 'unread',
      createdAt: new Date().toISOString(),
      extra: {
        experience: 5,
        badge: '坚持者'
      }
    }
  ],

  // User-specific data (will be populated based on user actions)
  evaluationHistory: [],
  gameRecords: [],
  dailyHistory: []
};

// Helper functions to simulate database operations
const findUserByUsername = (username) => {
  return mockData.users.find(user => user.username === username);
};

const findUserById = (id) => {
  return mockData.users.find(user => user.id === parseInt(id));
};

const createUser = (userData) => {
  const newUser = {
    id: mockData.users.length + 1,
    ...userData,
    createdAt: new Date().toISOString(),
    updatedAt: new Date().toISOString()
  };
  mockData.users.push(newUser);
  return newUser;
};

module.exports = {
  mockData,
  findUserByUsername,
  findUserById,
  createUser
};
